package com.niubi.yygh.user.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.niubi.yygh.cmn.client.DictFeignClient;
import com.niubi.yygh.enums.DictEnum;
import com.niubi.yygh.model.user.Patient;
import com.niubi.yygh.user.mapper.PatientMapper;
import com.niubi.yygh.user.service.PatientService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 就诊人表 服务实现类
 * </p>
 *
 * @author 牛俊杰
 * @since 2022-03-28
 */
@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements PatientService {

  @Autowired
  DictFeignClient dictFeignClient;

  @Override
  public List<Patient> findAllUserId(Long userId) {
    QueryWrapper<Patient> wrapper = new QueryWrapper<>();
    wrapper.eq("user_id",userId);
    List<Patient> patientList = baseMapper.selectList(wrapper);
    patientList.stream().forEach(item->{
      this.packagePatient(item);
    });

    return patientList;
  }

  @Override
  public Patient getPatientId(Long id) {
    return this.packagePatient(baseMapper.selectById(id));
  }

  private Patient packagePatient(Patient patient) {
    String certificatesTypeString = dictFeignClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(), patient.getCertificatesType());
    //获取省市区编码对应名称
    //省
    String provinceString = dictFeignClient.getName(patient.getProvinceCode());
    //市
    String cityString = dictFeignClient.getName(patient.getCityCode());
    //区
    String districtString = dictFeignClient.getName(patient.getDistrictCode());
    //封装到patient中
    patient.getParam().put("certificatesTypeString", certificatesTypeString);
    // patient.getParam().put("contactsCertificatesTypeString", contactsCertificatesTypeString);
    patient.getParam().put("provinceString", provinceString);
    patient.getParam().put("cityString", cityString);
    patient.getParam().put("districtString", districtString);
    patient.getParam().put("fullAddress", provinceString + cityString + districtString + patient.getAddress());
    return patient;

  }
}
